﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>测试</title>
    <script src="../js/layui/layui.js"></script>
    <link href="../js/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <div>测试</div>
    <button id="text" class="layui-btn">测试跨域</button>
    <button id="image" class="layui-btn">测试上传图片</button>
    <img id="image1" />
    <img id="image2" />
</body>
</html>
<script type="text/javascript">

    
    //主动加载jquery模块
    layui.use(['jquery', 'layer','upload'], function () {
        var $ = layui.$ ,//重点处
            layer = layui.layer,
            upload = layui.upload;

        //后面就跟你平时使用jQuery一样
        var httpurl = "http://localhost:36137";
        var imagedata = new Object();
        imagedata.Master = '123455';
        imagedata.Module = 'new';
        //上传图片
        upload.render({
            elem: '#image',
            url: httpurl+'/api/Upload/Image',
            data: imagedata,
            accept: 'images',
            done: function (res) {
                alert(res.msg);
                $("#image1").attr('src', httpurl + res.data.AnnexUrl);
                $("#image2").attr('src', httpurl + res.data.thumbnail);
            },
            error: function () {

            }
        })
        
        var device = layui.device();//获取操作系统
        $("#text").click(function () {
            var login = new Object();
            login.UserLogin = 'wp';
            login.UserPaws = 'wp';
            login.App = 'm6';
            $.ajax({
                url: 'http://localhost:36137/api/Public/Login',
                type: 'post',
                contentType: 'application/json',
                data: JSON.stringify(login),
                success: function (data) {
                    data = JSON.parse(data);
                    alert(data.msg);
                },
                error: function () {
                    alert('error');
                }

            })
        })
        
    });

    
</script>